import { Dispatch, UnknownAction } from "redux";
import { ListType, resetList, setList } from "../../reducer/list";

export const dealListData = {
  otherFilter: () => {},
  recommend: (dispatch: Dispatch<UnknownAction>) => {
    dispatch(resetList());
  },
  time: (
    dispatch: Dispatch<UnknownAction>,
    state: boolean,
    list: ListType[]
  ) => {
    const newList = [...list];
    state
      ? newList.sort((a, b) => a.seconds - b.seconds)
      : newList.sort((a, b) => b.seconds - a.seconds);
    dispatch(setList(newList));
  },
  price: (
    dispatch: Dispatch<UnknownAction>,
    state: boolean,
    list: ListType[]
  ) => {
    const newList = [...list];
    state
      ? newList.sort((a, b) => a.realPrice - b.realPrice)
      : newList.sort((a, b) => b.realPrice - a.realPrice);
    dispatch(setList(newList));
  },
};
